require("dotenv").config();

const app = require("./app");
const connectDB = require("./config/db");

const PORT = process.env.PORT || 3000;

async function bootstrap() {
    try {
        await connectDB();
        app.listen(PORT, () => {
            console.log(`🚀 Server listening on http://localhost:${PORT}`);
        });
    } catch (err) {
        console.error("启动失败:", err);
        process.exit(1);
    }
}

bootstrap();

// 捕获未处理异常，便于排查
process.on("unhandledRejection", (reason) => {
    console.error("unhandledRejection:", reason);
});
process.on("uncaughtException", (err) => {
    console.error("uncaughtException:", err);
    process.exit(1);
});
